<?php
class classSharedProduct{
    public function getSharedProductsList($iItemID){
        if(trim($iItemID)=='' or !is_numeric($iItemID) or $iItemID<1) return '';

        $sql_result = mysql_query('
            SELECT Shared_Product_ID
            FROM shared_products
            WHERE Product_ID = '.$iItemID.'
        ');


        if(mysql_affected_rows()<1) return '';

        $_PS = new classProductService();
        $_ID = new classItemDetail();
        $_Price = new classPriceExport();
        $_Skin = new classTemplate();

        $result = '
            <br>
            <br>
            <br>
                <font class="css_shared_list_caption">
                    '._i18n_product_WE_ADVICE_FOR_THIS_PRODUCT_.':
                </font>
            <br>';
        $result.= '<input type="hidden" id="ProductType" name="ProductType">';
        $result.= '<table cellpadding="0" cellspacing="0" class="css_shared_product_main_container">';
        while($sql_array_product = mysql_fetch_object($sql_result)){
            $Product        = $_PS->getProductInfo($sql_array_product->Shared_Product_ID);
            $product_image  = $_ID->getImage($sql_array_product->Shared_Product_ID, true);
            $product_name   = $this->makeLink($sql_array_product->Shared_Product_ID, $Product['Product_Name']);
            $product_price  = $_Price->simplePrice($sql_array_product->Shared_Product_ID,1);

            $result.= '<tr><td style="width:100%;padding:0; margin:0;">';
            include $_Skin->getActual().'/shared_product.inc.php';
            $result.= '</td></tr>';
        }
        $result.= '</table>';

        return $result;
    }

    private function makeLink($iPID, $sText){
        return '
            <a
                href="'._URL_INACTIVE_ADDR_.'"
                onclick="
                    document.getElementById(\'ProductType\').value = \'shared\';
                    document.getElementById(\'Show_Product_Detail_By_ID\').value = '.$iPID.';
                    classItemDetail();
                "
            >
                '.$sText.'
            </a>
        ';
    }
}
?>
